<{include file="public_html/header.html"}>
<{include file="public_html/left_menu.html"}>
<script type="text/javascript" charset="utf-8" src="/static/public/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/public/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/static/public/ueditor/lang/zh-cn/zh-cn.js"></script>
<style>
	.ss_document_box{position: relative;}
	.ss_document_box .layui-icon{position: absolute; left: 38px; top: 0;}
</style>
<blockquote class="layui-elem-quote"><{$action}></blockquote>

<form class="layui-form layui-form-pane" method="post" id="form_add_role">
	<input type="hidden" name="id" value="<{$topic_info['id']|default:'0'}>" />
	<div class="layui-form-item">
		<label class="layui-form-label">科目</label>
		<div class="layui-input-block">
			<select name="subject_id" id="subject" lay-filter="subject" lay-verify="required">
				<option value="0">请选择科目</option>
				<{foreach from=$subject item=item}>
					<option value="<{$item.id}>" <{if $topic_info['subject_id']|default:"33" eq $item.id}>selected="selected"<{/if}>><{$item.name}></option>
				<{/foreach}>
			</select>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">课本</label>
		<div class="layui-input-block">
			<select name="book_id" id="book" lay-filter="book" lay-verify="required">
				<option value="0">请选择课本</option>
				<{if isset($book_list) AND $book_list|count  > 0}>
				<{foreach from=$book_list item=book}>
					<option value="<{$book.id}>" <{if $book.id == $topic_info.book_id|default:"27"}> selected <{/if}>><{$book.title}></option>
				<{/foreach}>
				<{/if}>
			</select>
			<input type="hidden" id="book_name" name="book_name" />
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">章节</label>
		<div class="layui-input-block">
			<select name="chapter_id" id="chapter_id" lay-verify="required">
				<option value="0">请选择章节</option>
				<{if isset($chapter_list_data) AND $chapter_list_data|count  > 0}>
					<{foreach from=$chapter_list_data item=item}>
						<!-- <optgroup label="<{$item.title}>"> -->
						<option <{if $item.id == $topic_info.chapter_id|default:332}> selected <{/if}> value="<{$item.id}>"><{$item.title}></option>
						<{if $item.sub|count > 0}>
							<{foreach from=$item.sub item=item1}>
								<option <{if $item1.id == $topic_info.chapter_id|default:332}> selected <{/if}> value="<{$item1.id}>">----<{$item1.title}></option>
							<{/foreach}>
						<{/if}>
						<!-- </optgroup> -->
					<{/foreach}>
				<{/if}>
			</select>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">题目类型</label>
		<div class="layui-input-block">
			<select name="type" lay-verify="required" lay-filter="q_type" id="q_type" <{if $topic_info.type|default:"" > 0}> disabled <{/if}>>
				<option value="5" <{if 5 == $topic_info.type|default:""}> selected <{/if}>>填空题</option>
			</select>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">难度等级</label>
		<div class="layui-input-block">
			<input type="radio" name="difficulty_level" value="1" title="难" <{if $topic_info.difficulty_level|default:"" == 1}> checked <{/if}>>
			<input type="radio" name="difficulty_level" value="2" title="中" <{if $topic_info.difficulty_level|default:"" == 2 || !isset($topic_info)}> checked <{/if}>>
			<input type="radio" name="difficulty_level" value="3" title="易" <{if $topic_info.difficulty_level|default:"" == 3}> checked <{/if}>>
		</div>
	</div>

	<div class="layui-form-item layui-form-text" id="html_subject_text">
		<label class="layui-form-label">题目内容<span id="tiankong_tishi" style="color:red; padding-left: 10px;">提示：填空题的题目内容中每4个“_”(例:____，)符作为一个题目答案选项</span></label>
		<div class="layui-input-block">
			<!-- 加载编辑器的容器 -->
		    <script id="container" name="subject_text" type="text/plain">
		        <{$topic_info.subject_text|default:""}>
		    </script>
		    <!-- 配置文件 -->
		    <script type="text/javascript" src="/static/public/ueditor/ueditor.config.js"></script>
		    <!-- 编辑器源码文件 -->
		    <script type="text/javascript" src="/static/public/ueditor/ueditor.all.js"></script>
		    <!-- 实例化编辑器 -->
		    <script type="text/javascript">
		        var ue = UE.getEditor('container');
		    </script>
		</div>
	</div>

	<div id="an_tiankong_box">
		<{if isset($topic_result) AND $topic_result|count > 0}>
			<{foreach from=$topic_result key=key item=item}>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">题目答案<{$letter[$key]}></label>
					<div class="layui-input-block">
						<input type="text" name="an_choice_text[1]" lay-verify="title" value="<{$item.answer_text}>" autocomplete="off" class="layui-input" value="对" disabled style="width: 500px;" disabled>
					</div>
				</div>
			</div>
			<{/foreach}>
		<{else}>
		
		<div class="layui-form-item">
			<a href="javascript:;" class="layui-btn layui-btn-primary add_text"><i class="layui-icon"></i>新增文本</a>
			<a href="javascript:;" class="layui-btn layui-btn-primary add_symbol"><i class="layui-icon"></i>新增符号</a>
			<a href="javascript:;" class="layui-btn layui-btn-primary add_number"><i class="layui-icon"></i>新增数字</a>
		</div>
		<{/if}>
	</div>

	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">答案解析</label>
		<div class="layui-input-block">
			<textarea class="layui-textarea layui-hide editor" name="analysis" lay-verify="content" id="editor2"><{$topic_info.analysis|default:""}></textarea>
		</div>
	</div>

	<div class="layui-input-block">
		<button class="layui-btn" lay-submit lay-filter="sub_topic">保存</button>
	</div>
</form>
<{include file="public_html/footer.html"}>
<script>
	layui.use(['form', 'jquery', 'element'], function(){
		var layedit = layui.layedit,form = layui.form(),$ = layui.jquery, element = layui.element();
		/**
		 * book_id
		 * @param  {[type]} data){			var ii                                                         [description]
		 * @param  {[type]} success:      function(result){					layer.close(ii);					if(result.code [description]
		 * @return {[type]}               [description]
		 */
		form.on('select(subject)', function(data){
			var ii = layer.load();
			var subject_id = $(data.elem).val();
			$("#book").html('<option value="0">请选择课本</option>');
			form.render('select');
			$.ajax({
				type: "POST",
				url: "/topic/ignore_get_books",
				dataType:"json",
				data:{subject_id:subject_id},
				success: function(result){
					layer.close(ii);
					if(result.code == 1){
						var html ='';
						$.each(result.chapter_list, function(i, obj) {
							$("#book").append('<option value="'+obj.id+'">'+obj.title+'</option>');
						});
						
						form.render('select');
					}
				}
			});
		});

		form.on('select(book)', function(data){
			var ii = layer.load();
			var book_id = $(data.elem).val();
			$("#chapter_id").html('<option value="0">请选择章节</option>');
			form.render('select');
			$.ajax({
				type: "POST",
				url: "/topic/ignore_get_book_chapter",
				dataType:"json",
				data:{book_id:book_id},
				success: function(result){
					layer.close(ii);
					if(result.code == 1){
						var html ='';
						$.each(result.chapter_list, function(i, obj) {
							html += '<option value="'+obj.id+'">'+obj.title+'</option>';
							if(obj.sub){
								$.each(obj.sub, function(j, obj1) {
									html += '<option value="'+obj1.id+'">----'+obj1.title+'</option>';
								});
							}
							// html += '</optgroup>'
						});
						$("#chapter_id").append(html);
						$("#book_name").val($("#book option:selected").text())
						form.render('select');
					}
				}
			});
		});

		$(".add_text").click(function(){
			var _this = $(this);
			var tiankong_total = _this.closest("#an_tiankong_box").find(".tiankong_answer").length;
			var index = tiankong_total+1;
			var html = '<div class="layui-form-item">';
			html +=	'<label class="layui-form-label">题目答案' + index +'</label>';
			html +=	'<div class="layui-input-block">';
			html +=	'<input type="text" placeholder="文本" name="an_tiakong[text]['+index+']" lay-verify="required" autocomplete="off" class="layui-input tiankong_answer">';
			html += '</div></div>';
			_this.closest(".layui-form-item").before(html);
		});

		$(".add_symbol").click(function(){
			var _this = $(this);
			var tiankong_total = _this.closest("#an_tiankong_box").find(".tiankong_answer").length;
			var index = tiankong_total+1;
			var html = '<div class="layui-form-item">';
			html +=	'<label class="layui-form-label">题目答案' + index +'</label>';
			html +=	'<div class="layui-input-block">';
			html += '<select name="an_tiakong[symbol]['+index+']" class="tiankong_answer" lay-search>';
	    	html +=	'<option value="0">选择符号</option>';
	    	html +=	'<option value="+">+</option>';
	    	html +=	'<option value="-">-</option>';
	    	html +=	'<option value="*">*</option>';
	    	html +=	'<option value="/">/</option>';
	    	html +=	'<option value="(">(</option>';
	    	html +=	'<option value=")">)</option>';
	    	html +=	'<option value=">">></option>';
	    	html +=	'<option value="≥">≥</option>';
	    	html +=	'<option value="<"><</option>';
	    	html +=	'<option value="≤">≤</option>';
	    	html +=	'<option value="=">=</option>';
	    	html +=	'<option value="[">[</option>';
	    	html +=	'<option value="]">]</option>';
    		html +=	'</select>';
    		html += '</div></div>';
    		_this.closest(".layui-form-item").before(html);
    		form.render('select');
		})

		$(".add_number").click(function(){
			var _this = $(this);
			var tiankong_total = _this.closest("#an_tiankong_box").find(".tiankong_answer").length;
			var index = tiankong_total+1;
			var html = '<div class="layui-form-item">';
			html +=	'<label class="layui-form-label">题目答案' + index +'</label>';
			html +=	'<div class="layui-input-block">';
			html +=	'<input type="number" placeholder="数字" name="an_tiakong[number]['+index+']" lay-verify="required" autocomplete="off" class="layui-input tiankong_answer">';
			html += '</div></div>';
			_this.closest(".layui-form-item").before(html);
		});

	});

	
</script>